<template>
  <el-card class="zhexian">
    <div ref="zhexian" style="height: 280px"></div>
  </el-card>
</template>

<script>
import * as echarts from 'echarts'
import { getData } from '@/api/index.js'

export default {
  mounted() {
    getData().then(({ data }) => {
      // console.log(data)
      const echartszx = echarts.init(this.$refs.zhexian)
      const { orderData } = data.data
      // console.log(orderData[0].date)
      let echartszhexian = {}
      const date = Object.values(orderData[0].date)
      const xAxis = Object.keys(orderData[0].data[0])
      // const xAxis = Object.values(orderData[0].data[0])
      // const date = Object.values(orderData[0].date)
      // console.log(date);
      // console.log(xAxis)
      echartszhexian.xAxis = {
        data: date
      }
      echartszhexian.tooltip = {
        trigger: 'item'
      }
      echartszhexian.yAxis = {}
      echartszhexian.legend = {
        data: xAxis
      }
      echartszhexian.series = []
      xAxis.forEach(key => {
        echartszhexian.series.push({
          name: key,
          data: orderData[0].data.map(item => item[key]),
          type: 'line'
        })
      })
      // console.log(echartszhexian)
      echartszx.setOption(echartszhexian)
    })
  }
}
</script>

<style lang="less" scoped>
.zhexian {
  height: 280px;
  // background-color: pink;
}
</style>
